﻿using System.Windows;
using System.Windows.Documents;
using System.Windows.Shapes;
using System.Xml.Linq;
using FirstFloor.Documents.Annotations;
using FirstFloor.Documents.Annotations.Storage;

namespace FirstFloor.Documents.Presentation.Annotations
{
    /// <summary>
    /// Represents a text strikethrough annotation.
    /// </summary>
    public class Strikethrough
        : TextAnnotation
    {
        /// <summary>
        /// Identifies the strikethrough annotation type.
        /// </summary>
        public static readonly XName TypeStrikethrough = XName.Get("Strikethrough", AnnotationStore.NamespaceAnnotations);

        /// <summary>
        /// Initializes a new instance of the <see cref="Strikethrough"/> class.
        /// </summary>
        public Strikethrough()
            : base(TypeStrikethrough)
        {
        }

        /// <summary>
        /// Renders the annotation for given glyphs element in specified rectangle.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="glyphs">The glyphs.</param>
        /// <param name="rectangle">The rectangle.</param>
        protected override void RenderGlyphsAnnotation(AnnotationRenderContext context, Glyphs glyphs, Rect rectangle)
        {
            context.AnnotationLayer.Children.Add(new Line() {
                Stroke = glyphs.Fill,         // strikethrough always same color as glyphs fill
                StrokeThickness = 1,
                X1 = rectangle.Left,
                Y1 = (rectangle.Top + rectangle.Bottom) / 2,
                X2 = rectangle.Right,
                Y2 = (rectangle.Top + rectangle.Bottom) / 2
            });
        }
    }
}
